/*
 * server_cfg.h
 *
 *  Created on: Dec 2, 2013
 *      Author: killerg
 */

#ifndef SERVER_CFG_H_
#define SERVER_CFG_H_


#include "share/cfg_file.h"

struct server_cfg_t {
    bool init(const char* prefix) {
        if (!file.load("server.txt", prefix)) {
            return false;
        }

        ServerId          = file.get_int("serverid", 0);
        ListenClientIp    = file.get_str("listen_client_ip", "0.0.0.0");
        ListenClientPort  = file.get_int("listen_client_port", 9001);
        ListenConsoleIp   = file.get_str("listen_console_ip", "0.0.0.0");
        ListenConsolePort = file.get_int("listen_console_port", 9006);
        LogonIp           = file.get_str("logon_ip", "127.0.0.1");
        LogonPort         = file.get_int("logon_port", 8001);
        BillIp            = file.get_str("bill_ip", "127.0.0.1");
        BillPort          = file.get_int("bill_port", 8002);
        BillDbHost        = file.get_str("bill_db_host", "");
        BillDbBucket      = file.get_str("bill_db_bucket", "");
        DbHost            = file.get_str("db_host", "");
        DbBucket          = file.get_str("db_bucket", "" );
        LogDbHost         = file.get_str("log_db_host", "");
        LogDbBucket       = file.get_str("log_db_bucket", "" );
        gm_cmd            = file.get_bool("gm_cmd", false);
        DecodeClient      = file.get_bool("decode_client", false);
        GmAccount         = file.get_str("gm_account", "" );
        ServerName        = file.get_str("server_name", "" );
        MaxClient     	  = file.get_int("max_client", 1000);
        NewServer		  = file.get_int("new_server", 0);
        if (NewServer) {
        	ServerName.append("(新区)");
        } else {
        	ServerName.append("(火爆)");
        }

        if (DbHost.empty() || DbBucket.empty())
            return false;

        return true;
    }
    void destroy() {
    }

    cfg_file_t file;

    int32_t ServerId;
    std::string ListenClientIp;
    int32_t ListenClientPort;
    std::string ListenConsoleIp;
    int32_t ListenConsolePort;
    std::string LogonIp;
    int32_t LogonPort;
    std::string BillIp;
    int32_t BillPort;
    std::string BillDbHost;
    std::string BillDbBucket;
    std::string DbHost;
    std::string DbBucket;
    std::string LogDbHost;
    std::string LogDbBucket;
    bool gm_cmd;
    bool DecodeClient;
    std::string GmAccount;
    std::string ServerName;
    int32_t MaxClient;
    bool NewServer;
//    std::string Prefix;
};




#endif /* SERVER_CFG_H_ */
